__author__ = 'st316'
'''
Write a function to find the longest common prefix string amongst an array of strings.
注意：
输入列表为空
'''


class Solution:
    # @return a string
    def longestCommonPrefix(self, strs):
        prefix = ''
        if len(strs) == 0:
            return prefix
        i = 0
        while True:
            if i == len(strs[0]):
                break
            cur = strs[0][i]
            flag1 = True
            flag2 = False
            for s in strs[1:]:
                if i == len(s):
                    flag1 = False
                    flag2 = True
                    break
                if s[i] != cur:
                    flag1 = False
                    break
            if flag1:
                prefix += cur
            if not flag1 or flag2:
                break
            i += 1
        return prefix


if __name__ == '__main__':
    strs = ["aca", "acba"]
    s = Solution()
    print s.longestCommonPrefix(strs)